package com.derbysoft.dswitch.adapter.ihg.web.action.admin.reservation;

import com.derbysoft.dswitch.adapter.ihg.common.domain.ReservationModifyItem;
import com.derbysoft.dswitch.adapter.ihg.common.repository.ResModifyItemRepository;
import com.derbysoft.dswitch.adapter.ihg.common.repository.ReservationRepository;
import com.derbysoft.dswitch.adapter.ihg.web.action.support.PaginateActionSupport;
import com.opensymphony.xwork2.ActionContext;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class ReservationAction extends PaginateActionSupport {

    @Autowired
    private ReservationRepository reservationRepository;

    private ReservationCondition condition;

    private List<ReservationModifyItem> reservationModifyItems;

    @Autowired
    private ResModifyItemRepository resModifyItemsRepository;


    @Action("list")
    public String list() {
        ActionContext.getContext().setLocale(ServletActionContext.getRequest().getLocale());
        reservationRepository.paginater(condition, getPaginater());
        return SUCCESS;
    }

    @Actions({@Action("view-ajax"), @Action("view")})
    public String view() {
        if (StringUtils.isBlank(condition.getErsp())) {
            return INPUT;
        }
        reservationModifyItems = resModifyItemsRepository.loadByErsp(condition.getErsp());
        return SUCCESS;
    }

    public ReservationCondition getCondition() {
        return condition;
    }

    public void setCondition(ReservationCondition condition) {
        this.condition = condition;
    }

    public List<ReservationModifyItem> getReservationModifyItems() {
        return reservationModifyItems;
    }

    public void setReservationModifyItems(List<ReservationModifyItem> reservationModifyItems) {
        this.reservationModifyItems = reservationModifyItems;
    }
}